
<template>
    <div id="app">
        <headerView></headerView>
        <router-view class="main-whole"></router-view>
        <footerView></footerView>
        <login v-if="login"></login>
        <register v-if="reg"></register>
    </div>
</template>
<script>
    import headerView from './components/header.vue';
    import footerView from './components/footer.vue';
//  import login from './components/login.vue';
	import login from './pages/user/login.vue'
	import register from './pages/user/register.vue'
    import { mapState } from 'vuex';
    export default {
        components:{
            headerView,
            footerView,
            login,
            register
          },
        data () {
            return {
                loading: false,
                user_id:'',
                depth:0,
                categoryList:[]
            }
        },
        computed: mapState({
            spinShow: 'mainLoading',
            login:'loginState',
            reg:'regState',
        }),
        watch: {
            // 监听变化
            loading() {
                // true 的话就开启这个的头部加载调
                if ( this.loading ) {

                // false 的话就关闭，开启共用
                }else {

                }
            }
        },
        created() {
            this.getCarousel();
        },
        methods:{
            // 获取当前登录用户
            getAuth() {
                let url_token = window.localStorage.getItem('ccm-token');
                this.$http.get('/member/me').then(ret => {
                    this.user_id = ret.data.data.id;
                }).catch(err => {

                })
            },
            getCarousel() {
                this.$http.get('/category/list',{
                    params:{
                        include:"childrens.childrens.childrens"
                    }
                })
                .then(res => {
                    this.categoryList = res.data.data;
                    this.getTree(this.categoryList);
                    this.$store.dispatch('setLawList',{
                        depth:this.depth+1,
                        name:'法律法规',
                        children:this.categoryList
                    });
                }).catch(err => {
                    this.$Message.error( 'category');
                })
            },
            getTree(node){
                if(node && node.length != 0){
                    node.forEach((item,index)=>{
                        item.label = item.name;
                        item.value = item.id;
                        this.depth = this.depth > item.depth ? this.depth : item.depth;
                        if(item.childrens){
                            item.children = item.childrens.data;
                            this.getTree(item.childrens.data);
                            delete item.childrens;
                        }
                    })
                }
            }
        }
    }
</script>
<style type="text/css">
    @import './assets/css/main.css';
</style>

